app.controller("login", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$scope.page.show = true;
	$scope.page.hide = false;
	$scope.pageshow = function() {
		$scope.page.show = true;
		$scope.page.hide = false;
	}
	$scope.pagehide = function() {
		$scope.page.show = false;
		$scope.page.hide = true;
	}
	var channel = localStorage.getItem("channel")
	if(channel==30003){
		$(".father_warp").show()
	}else{
		$(".father_warp").hide()
	}
	var phoneUser = localStorage.getItem("userphone")
	if(!phoneUser){
		$(".userphone").attr("placeholder","请输入手机号")
		$(".userPhone").attr("placeholder","请输入手机号")
	}else{
		$(".userphone").attr("value",phoneUser)
		$(".userPhone").attr("value",phoneUser)
	}
	$(".icon-weixin").click(function(){
		window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8f0843a3e3eeb030&redirect_uri=http://web.tl178.cn/login/wxlogin&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
	})
	//账号密码登录
	$(".login_btn").click(function(){
			var userphone = $(".userphone").val();
			if(!userphone) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				var reg = new RegExp(/^1[34578]\d{9}$/);
				if(!reg.test(userphone) || userphone.length != 11) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入正确的手机号");
					$(".addressdialog").fadeOut(1200);
				} else {
					var psd = $(".password").val();
					if(!psd) {
						$(".addressdialog").show();
						$(".addressdialog").html("请输入密码");
						$(".addressdialog").fadeOut(1200);
					} else {
						$http({
							method: 'post',
							url: '' + $rootScope.Location + 'Login/verify',
							data: {
								mobile: userphone
							},
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
						}).success(function(data) {
							if(data.status == 1) {
								$(".addressdialog").show();
								$(".addressdialog").html("该手机号还未注册，请先注册");
								$(".addressdialog").fadeOut(1200);
								setTimeout(function() {
									$state.go("main.register")
								}, 1200)
							} else {
								$http({
									method: 'post',
									url: '' + $rootScope.Location + 'Login/login',
									data: {
										mobile: userphone,
										password: psd,
										type: 2
									},
									headers: {
										'Content-Type': 'application/x-www-form-urlencoded'
									},
								}).success(function(data) {
									if(data.status == 0) {
										$(".addressdialog").show();
										$(".addressdialog").html(data["message"]);
										$(".addressdialog").fadeOut(1200);
									} else {
										localStorage.setItem("user_ID", data["list"]["user_Id"])
										localStorage.setItem("token", data["list"]["token"])
										localStorage.setItem("userphone",userphone)
										$(".addressdialog").show();
										$(".addressdialog").html(data["message"]);
										$(".addressdialog").fadeOut(1200);
										setTimeout(function() {
											if(!localStorage.getItem("url")) {
												$state.go("main.home")
											} else {
												window.location.href = localStorage.getItem("url")
											}
										}, 1000)
									}
								})
							}
						})
					}
				}
			}
		})
		//验证码登录
	clearInterval($rootScope.waitTime)

	$(".btn").click(function() {
		if(!$(".userPhone").val()) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test($(".userPhone").val()) || $(".userPhone").val().length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Login/send',
					data: {
						mobile: $(".userPhone").val(),
						type: 2
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码发送成功");
					$(".addressdialog").fadeOut(1200);
					var wait = 60;
					$(".btn").attr("disabled", true);
					$(".btn").css({
						"color": "#B3B3B3"
					})
					$rootScope.waitTime = setInterval(function() {
						$(".btn").html("重新发送" + "(" + wait + ")")
						wait--
						if(wait < 0) {
							$(".btn").html("获取验证码")
							$(".btn").attr("disabled", false);
							$(".btn").css({
								"color": "#000"
							})
							clearInterval($rootScope.waitTime)
						}
					}, 1000)
				})
			}
		}

	})

	$(".login_btn2").click(function() {
		var userphone = $(".userPhone").val();
		if(!userphone) {
			$(".addressdialog").show();
			$(".addressdialog").html("请输入手机号");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test(userphone) || userphone.length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				var yanzheng = $(".yanzheng").val();
				if(!yanzheng) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入验证码");
					$(".addressdialog").fadeOut(1200);
				} else {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Login/verify',
						data: {
							mobile: userphone,
						},
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
					}).success(function(data) {
						if(data.status == 1) {
							$(".addressdialog").show();
							$(".addressdialog").html("该手机号还未注册，请先注册");
							$(".addressdialog").fadeOut(1200);
							setTimeout(function() {
								$state.go("main.register")
							}, 1200)
						} else {
							$http({
								method: 'post',
								url: '' + $rootScope.Location + 'Login/login',
								data: {
									mobile: userphone,
									code: yanzheng,
									type: 1
								},
								headers: {
									'Content-Type': 'application/x-www-form-urlencoded'
								},
							}).success(function(data) {
								if(data.status == 0) {
									$(".addressdialog").show();
									$(".addressdialog").html(data["message"]);
									$(".addressdialog").fadeOut(1200);
								} else {
									localStorage.setItem("user_ID", data["list"]["user_Id"])
									localStorage.setItem("token", data["list"]["token"])
									$(".addressdialog").show();
									$(".addressdialog").html(data["message"]);
									$(".addressdialog").fadeOut(1200);
									setTimeout(function() {
										if(!localStorage.getItem("url")) {
											$state.go("main.home")
										} else {
											window.location.href = localStorage.getItem("url")
										}
									}, 1000)
								}
							})
						}
					})
				}
			}
		}
	})
}])

app.controller("register", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	clearInterval($rootScope.waitTime)
	$(".login_psd button").click(function() {
		if(!$(".userphone").val()) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Login/send',
					data: {
						mobile: $(".userphone").val(),
						type: 1
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码发送成功");
					$(".addressdialog").fadeOut(1200);
					var wait = 60;
					$(".btn").attr("disabled", true);
					$(".btn").css({
						"color": "#B3B3B3"
					})
					$rootScope.waitTime = setInterval(function() {
						$(".btn").html("重新发送" + "(" + wait + ")")
						wait--
						if(wait < 0) {
							$(".btn").html("获取验证码")
							$(".btn").attr("disabled", false);
							$(".btn").css({
								"color": "#000"
							})
							clearInterval($rootScope.waitTime)
						}
					}, 1000)
				})
			}
		}
	})
	$(".login_btn").click(function() {
		var username = $(".username").val();
		var yanzheng = $(".yanzheng").val();
		var userphone = $(".userphone").val();
		var psd = $(".psd").val();
		var psd2 = $(".psd2").val();
//		var email = $(".email").val();
		var tuijian = $(".tuijian").val();
		if(!userphone) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test(userphone) || userphone.length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				if(!yanzheng) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码不能为空");
					$(".addressdialog").fadeOut(1200);
				} else {
					if(!username) {
						$(".addressdialog").show();
						$(".addressdialog").html("用户名不能为空");
						$(".addressdialog").fadeOut(1200);
					} else {
						if(!psd || !psd2) {
							$(".addressdialog").show();
							$(".addressdialog").html("密码或确认密码不能为空");
							$(".addressdialog").fadeOut(1200);
						} else {
//							var reg = new RegExp(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/);
//							if(!reg.test(email)) {
//								$(".addressdialog").show();
//								$(".addressdialog").html("邮箱格式有误");
//								$(".addressdialog").fadeOut(1200);
//							} else {
								$http({
									method: 'post',
									url: '' + $rootScope.Location + 'Login/verify',
									data: {
										mobile: userphone
									},
									headers: {
										'Content-Type': 'application/x-www-form-urlencoded'
									},
								}).success(function(data) {
									if(data.status == 1) {
										$http({
											method: 'post',
											url: '' + $rootScope.Location + 'Login/register',
											data: {
												mobile: userphone,
												nickname: username,
												password: psd,
												password1: psd2,
//												emal: email,
												code: yanzheng,
												superior:tuijian
											},
											headers: {
												'Content-Type': 'application/x-www-form-urlencoded'
											},
										}).success(function(data) {
											console.log(data)
											localStorage.setItem("user_ID", data["list"]["user_Id"])
											localStorage.setItem("token", data["list"]["token"])
											$(".addressdialog").show();
											$(".addressdialog").html(data.message);
											$(".addressdialog").fadeOut(1200);
											setTimeout(function() {
												if(!localStorage.getItem("url")) {
													$state.go("main.home")
												} else {
													window.location.href = localStorage.getItem("url")
												}
											}, 1000)
										})
									} else {
										$(".addressdialog").show();
										$(".addressdialog").html("该手机号已注册，请勿重复注册！");
										$(".addressdialog").fadeOut(1200);
									}
								})
							}
						}
					}
				
			}
		}
	})
}])
//第三方登陆注册
app.controller("registration", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	clearInterval($rootScope.waitTime)
	var href = window.location.href
	var absurl = href.split("?")[1]
	$scope.Name = decodeURI(absurl.split("&")[0].split("=")[1])
	var user_ID = absurl.split("&")[1].split("=")[1]	
	$(".login_psd button").click(function() {
		if(!$(".userphone").val()) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Login/send',
					data: {
						mobile: $(".userphone").val(),
						type: 1
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码发送成功");
					$(".addressdialog").fadeOut(1200);
					var wait = 60;
					$(".btn").attr("disabled", true);
					$(".btn").css({
						"color": "#B3B3B3"
					})
					$rootScope.waitTime = setInterval(function() {
						$(".btn").html("重新发送" + "(" + wait + ")")
						wait--
						if(wait < 0) {
							$(".btn").html("获取验证码")
							$(".btn").attr("disabled", false);
							$(".btn").css({
								"color": "#000"
							})
							clearInterval($rootScope.waitTime)
						}
					}, 1000)
				})
			}
		}
	})
	$(".login_btn").click(function() {
		var username = $(".username").val();
		var yanzheng = $(".yanzheng").val();
		var userphone = $(".userphone").val();
		var psd = $(".psd").val();
		var psd2 = $(".psd2").val();
//		var email = $(".email").val();
		var tuijian = $(".tuijian").val();
		if(!userphone) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test(userphone) || userphone.length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				if(!yanzheng) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码不能为空");
					$(".addressdialog").fadeOut(1200);
				} else {
						if(!psd || !psd2) {
							$(".addressdialog").show();
							$(".addressdialog").html("密码或确认密码不能为空");
							$(".addressdialog").fadeOut(1200);
						} else {
//							var reg = new RegExp(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/);
//							if(!reg.test(email)) {
//								$(".addressdialog").show();
//								$(".addressdialog").html("邮箱格式有误");
//								$(".addressdialog").fadeOut(1200);
//							} else {
								$http({
									method: 'post',
									url: '' + $rootScope.Location + 'Login/verify',
									data: {
										mobile: userphone
									},
									headers: {
										'Content-Type': 'application/x-www-form-urlencoded'
									},
								}).success(function(data) {
									if(data.status == 1) {
										$http({
											method: 'post',
											url: '' + $rootScope.Location + 'Login/bind_mobile',
											data: {
												user_Id:user_ID,
												mobile: userphone,
												nickname: username,
												password: psd,
												password1: psd2,
//												emal: email,
												code: yanzheng,
												superior:tuijian
											},
											headers: {
												'Content-Type': 'application/x-www-form-urlencoded'
											},
										}).success(function(data) {
											console.log(data)
																			
											if(data["status"]==1){
												$(".addressdialog").show();
												$(".addressdialog").html(data["message"]);
												$(".addressdialog").fadeOut(1200);
												localStorage.setItem("user_ID", data["list"]["user_Id"])
												localStorage.setItem("token", data["list"]["token"])
												setTimeout(function() {
													if(!localStorage.getItem("url")) {
														$state.go("main.home")
													} else {
														window.location.href = localStorage.getItem("url")
													}
												}, 1000)
											}else{
												$(".addressdialog").show();
												$(".addressdialog").html(data["message"]);
												$(".addressdialog").fadeOut(1200);
											}
										})
									} else {
										$(".addressdialog").show();
										$(".addressdialog").html("该手机号已注册，请勿重复注册！");
										$(".addressdialog").fadeOut(1200);
									}
								})
							}
						}
//				}
			}
		}
	})
}])
app.controller("setpsd", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$scope.confirmPassword = function() {
		var psd1 = $(".new_psd").val();
		var psd2 = $(".sibmit_new_psd").val()
		if(!psd1) {
			$(".addressdialog").show();
			$(".addressdialog").html("新密码不能为空");
			$(".addressdialog").fadeOut(1200);
			//			plus.nativeUI.toast("新密码不能为空");
		} else {
			if(psd1 != psd2) {
				$(".addressdialog").show();
				$(".addressdialog").html("两次输入的密码不一致！");
				$(".addressdialog").fadeOut(1200);
				//				plus.nativeUI.toast("两次输入的密码不一致");
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Member/set_password',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						password: psd1,
						password1: psd2
					},
				}).success(function(data) {
					if(data["status"] == 1) {
						$state.go("main.personal")
						$(".addressdialog").show();
						$(".addressdialog").html("密码修改成功");
						$(".addressdialog").fadeOut(1200);
							//						plus.nativeUI.toast("密码修改成功");
					} else {
						//						plus.nativeUI.toast(data["message"]);
					}
				})
			}
		}
	}

}])

app.controller("phoneyz", ["$scope", "$stateParams", "$rootScope", "$state", "$http", function($scope, $stateParams, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	if($stateParams.type == 1) {
		$scope.phoneyz = true
		$scope.nicknameyz = false;
		$(".portrait_warp button").click(function() { //获取验证码
			if(!$(".userphone").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("手机号不能为空");
				$(".addressdialog").fadeOut(1200);
			} else {
				var reg = new RegExp(/^1[34578]\d{9}$/);
				if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入正确的手机号");
					$(".addressdialog").fadeOut(1200);
				} else {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Login/send',
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							mobile: $(".userphone").val(),
							type: 4
						},
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
					}).success(function(data) {
						$(".addressdialog").show();
						$(".addressdialog").html("验证码发送成功");
						$(".addressdialog").fadeOut(1200);
						var wait = 60;
						$(".btn").attr("disabled", true);
						$(".btn").css({
							"color": "#B3B3B3"
						})
						$rootScope.waitTime = setInterval(function() {
							$(".btn").html("重新发送" + "(" + wait + ")")
							wait--
							if(wait < 0) {
								$(".btn").html("获取验证码")
								$(".btn").attr("disabled", false);
								$(".btn").css({
									"color": "#000"
								})
								clearInterval($rootScope.waitTime)
							}
						}, 1000)
					})
				}
			}
		})
		$scope.setpaypsd = function(){
			if(!$(".userphone").val() || !$(".yanzheng").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入手机号和验证码");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Account/pay_next',
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						tel: $(".userphone").val(),
						code: $(".yanzheng").val()
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					console.log(data)
					if(data["status"] == 1) {
						$state.go("main.setpaypsd")
					} else {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
					}
				})
			}
		}
	}
	if($stateParams.type == 2) {
		$scope.nicknameyz = true;
		$scope.phoneyz = false;
		$scope.setpaypsd = function() { //修改昵称
			if(!$(".nick").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html('昵称不能为空');
				$(".addressdialog").fadeOut(1200);
			} else {
				if($(".nick").val().length > 10) {
					$(".addressdialog").show();
					$(".addressdialog").html('昵称不能大于十位数');
					$(".addressdialog").fadeOut(1200);
				} else {

					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Member/personal',
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							nickname: $(".nick").val()
						},
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
					}).success(function(data) {
							if(data["status"]==1){
								$(".addressdialog").show();
								$(".addressdialog").html(data["message"]);
								$(".addressdialog").fadeOut(1200);
								$state.go("main.personal")
							}			
					})
				}
			}
		}
	}
}])

app.controller("setpaypsd", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$scope.setpaypsd = function() {
		var psd1 = $(".new_psd").val();
		var psd2 = $(".sibmit_new_psd").val()
		if(!psd1) {
			$(".addressdialog").show();
			$(".addressdialog").html("新密码不能为空");
			$(".addressdialog").fadeOut(1200);
			//			plus.nativeUI.toast("新密码不能为空");
		} else {
			if(psd1 != psd2) {
				$(".addressdialog").show();
				$(".addressdialog").html("两次输入的密码不一致！");
				$(".addressdialog").fadeOut(1200);
				//				plus.nativeUI.toast("两次输入的密码不一致");
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Account/set_paypwd',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						password1: psd1,
						password2: psd2
					},
				}).success(function(data) {
					if(data["status"] == 1) {
						$state.go("main.personal")
							//plus.nativeUI.toast("密码修改成功");
					} else {
						//plus.nativeUI.toast(data["message"]);
					}
				})
			}
		}
	}
}])
//设置新手机号
app.controller("setphone", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$(".portrait_warp button").click(function() { //获取验证码
			if(!$(".userphone").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("手机号不能为空");
				$(".addressdialog").fadeOut(1200);
			} else {
				var reg = new RegExp(/^1[34578]\d{9}$/);
				if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入正确的手机号");
					$(".addressdialog").fadeOut(1200);
				} else {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Login/send',
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							mobile: $(".userphone").val(),
							type: 4
						},
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
					}).success(function(data) {
						$(".addressdialog").show();
						$(".addressdialog").html("验证码发送成功");
						$(".addressdialog").fadeOut(1200);
						var wait = 60;
						$(".btn").attr("disabled", true);
						$(".btn").css({
							"color": "#B3B3B3"
						})
						$rootScope.waitTime = setInterval(function() {
							$(".btn").html("重新发送" + "(" + wait + ")")
							wait--
							if(wait < 0) {
								$(".btn").html("获取验证码")
								$(".btn").attr("disabled", false);
								$(".btn").css({
									"color": "#000"
								})
								clearInterval($rootScope.waitTime)
							}
						}, 1000)
					})
				}
			}
		})
		$scope.setNewphone = function() {
			if(!$(".userphone").val() || !$(".yanzheng").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入手机号和验证码");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Account/pay_next',
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						tel: $(".userphone").val(),
						code: $(".yanzheng").val()
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					console.log(data)
					if(data["status"] == 1) {
						$state.go("main.setNewphone")
					} else {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
					}
				})
			}
		}	
}])	

app.controller("setphone", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$(".portrait_warp button").click(function() { //获取验证码
			if(!$(".userphone").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("手机号不能为空");
				$(".addressdialog").fadeOut(1200);
			} else {
				var reg = new RegExp(/^1[34578]\d{9}$/);
				if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入正确的手机号");
					$(".addressdialog").fadeOut(1200);
				} else {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Login/send',
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							mobile: $(".userphone").val(),
							type: 4
						},
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
					}).success(function(data) {
						$(".addressdialog").show();
						$(".addressdialog").html("验证码发送成功");
						$(".addressdialog").fadeOut(1200);
						var wait = 60;
						$(".btn").attr("disabled", true);
						$(".btn").css({
							"color": "#B3B3B3"
						})
						$rootScope.waitTime = setInterval(function() {
							$(".btn").html("重新发送" + "(" + wait + ")")
							wait--
							if(wait < 0) {
								$(".btn").html("获取验证码")
								$(".btn").attr("disabled", false);
								$(".btn").css({
									"color": "#000"
								})
								clearInterval($rootScope.waitTime)
							}
						}, 1000)
					})
				}
			}
		})
		$scope.setNewphone = function() {
			if(!$(".userphone").val() || !$(".yanzheng").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入手机号和验证码");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Account/pay_next',
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						tel: $(".userphone").val(),
						code: $(".yanzheng").val()
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					console.log(data)
					if(data["status"] == 1) {
						$state.go("main.personal")
					} else {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
					}
				})
			}
		}	
}])
//忘记密码
app.controller("forgetPassword", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	$(".personal_list .btn").click(function() {
		if(!$(".userphone").val()) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test($(".userphone").val()) || $(".userphone").val().length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Login/send',
					data: {
						mobile: $(".userphone").val(),
						type: 3
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码发送成功");
					$(".addressdialog").fadeOut(1200);
					var wait = 60;
					$(".btn").attr("disabled", true);
					$(".btn").css({
						"color": "#B3B3B3"
					})
					$rootScope.waitTime = setInterval(function() {
						$(".btn").html("重新发送" + "(" + wait + ")")
						wait--
						if(wait < 0) {
							$(".btn").html("获取验证码")
							$(".btn").attr("disabled", false);
							$(".btn").css({
								"color": "#000"
							})
							clearInterval($rootScope.waitTime)
						}
					}, 1000)
				})
			}
		}
	})
		$(".login_btn").click(function() {
		var yanzheng = $(".yanzheng").val();
		var userphone = $(".userphone").val();
		var psd = $(".psd").val();
		if(!userphone) {
			$(".addressdialog").show();
			$(".addressdialog").html("手机号不能为空");
			$(".addressdialog").fadeOut(1200);
		} else {
			var reg = new RegExp(/^1[34578]\d{9}$/);
			if(!reg.test(userphone) || userphone.length != 11) {
				$(".addressdialog").show();
				$(".addressdialog").html("请输入正确的手机号");
				$(".addressdialog").fadeOut(1200);
			} else {
				if(!yanzheng) {
					$(".addressdialog").show();
					$(".addressdialog").html("验证码不能为空");
					$(".addressdialog").fadeOut(1200);
				} else {
						if(!psd) {
							$(".addressdialog").show();
							$(".addressdialog").html("密码不能为空");
							$(".addressdialog").fadeOut(1200);
						} else {
								$http({
									method: 'post',
									url: '' + $rootScope.Location + 'Login/forget',
									data: {
										mobile: userphone,
										password:psd,
										code:yanzheng
									},
									headers: {
										'Content-Type': 'application/x-www-form-urlencoded'
									},
								}).success(function(data) {
									if(data["status"]==1){
										$(".addressdialog").show();
										$(".addressdialog").html(data["message"]);
										$(".addressdialog").fadeOut(1200);
										setTimeout(function(){
											$state.go("main.login")
										},1200)
									}else{
										$(".addressdialog").show();
										$(".addressdialog").html(data["message"]);
										$(".addressdialog").fadeOut(1200);
									}
								})
							}
						}
//				}
			}
		}
	})
	
}])